package com.fengze.business.service.impl;

import java.util.Collections;
import java.util.Date;
import java.util.List;

import com.fengze.business.domain.Payment;
import com.fengze.business.enums.BusiTypeEnum;
import com.fengze.business.enums.BusinessTypeEnums;
import com.fengze.business.mapper.PaymentMapper;
import com.fengze.common.annotation.AutoSetInsertValue;
import com.fengze.common.annotation.AutoSetUpdateValue;
import com.fengze.common.core.domain.model.LoginUser;
import com.fengze.common.utils.DateUtils;
import com.fengze.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fengze.business.mapper.AuditOpinionMapper;
import com.fengze.business.domain.AuditOpinion;
import com.fengze.business.service.IAuditOpinionService;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 审核意见Service业务层处理
 * 
 * @author lug
 * @date 2024-12-10
 */
@Service
public class AuditOpinionServiceImpl implements IAuditOpinionService 
{
    @Resource
    private AuditOpinionMapper auditOpinionMapper;


    @Resource
    private PaymentMapper paymentMapper;

    /**
     * 查询审核意见
     * 
     * @param id 审核意见主键
     * @return 审核意见
     */
    @Override
    public AuditOpinion selectAuditOpinionById(Long id)
    {
        return auditOpinionMapper.selectAuditOpinionById(id);
    }

    /**
     * 查询审核意见列表
     * 
     * @param auditOpinion 审核意见
     * @return 审核意见
     */
    @Override
    public List<AuditOpinion> selectAuditOpinionList(AuditOpinion auditOpinion)
    {
        return auditOpinionMapper.selectAuditOpinionList(auditOpinion);
    }

    /**
     * 新增审核意见
     * 
     * @param auditOpinion 审核意见
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @AutoSetInsertValue
    @Override
    public int insertAuditOpinion(AuditOpinion auditOpinion)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Payment payment = new Payment();
        payment.setAuditStatus(auditOpinion.getStatus());
        payment.setId(auditOpinion.getBusiId());
        paymentMapper.updatePayment(payment);
        auditOpinion.setBusiType(BusiTypeEnum.PAYMENT.getType());
        return auditOpinionMapper.insertAuditOpinion(auditOpinion);
    }

    /**
     * 修改审核意见
     * 
     * @param auditOpinion 审核意见
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @AutoSetUpdateValue
    @Override
    public int updateAuditOpinion(AuditOpinion auditOpinion)
    {
        return auditOpinionMapper.updateAuditOpinion(auditOpinion);
    }

    /**
     * 批量删除审核意见
     * 
     * @param ids 需要删除的审核意见主键
     * @return 结果
     */
    @Override
    public int deleteAuditOpinionByIds(Long[] ids)
    {
        return auditOpinionMapper.deleteAuditOpinionByIds(ids);
    }

    /**
     * 删除审核意见信息
     * 
     * @param id 审核意见主键
     * @return 结果
     */
    @Override
    public int deleteAuditOpinionById(Long id)
    {
        return auditOpinionMapper.deleteAuditOpinionById(id);
    }


    @Override
    public List<AuditOpinion> selectBusi(Long busiId, String type) {
        return auditOpinionMapper.selectByBusi(busiId,type);
    }
}
